﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Germany_EVO
{
    public partial class  DeBug : Form
    {
        private DeBug()
        {
            InitializeComponent();
        }
        private static DeBug debug1 = null;
        private static readonly object locker = new object();
        public void ChangeTime(string x)
        {
            if (checkBox1.Checked == true&&debug1!=null)
            {
                //this.Invoke(new Action(() => richTextBox1.AppendText(x)));
                richTextBox1.AppendText(x);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Clear();
        }

        private void DeBug_Load(object sender, EventArgs e)
        {
            checkBox1.Checked = true;
        }

        private void DeBug_FormClosing(object sender, FormClosingEventArgs e)
        {
           // MaluFrm.frmDebuglogIsOpen = false;
        }
        public static DeBug OpenFrm()
        {
            // 当第一个线程运行到这里时，此时会对locker对象 "加锁"，
            // 当第二个线程运行该方法时，首先检测到locker对象为"加锁"状态，该线程就会挂起等待第一个线程解锁
            // lock语句运行完之后（即线程运行完之后）会对该对象"解锁"
            if (debug1 == null)
            {
                lock (locker)
                {
                    if (debug1 == null)
                    {
                        debug1 = new DeBug();
                    }
                }
            }
            debug1.Focus();
            return debug1;
        }

        private void DeBug_FormClosed(object sender, FormClosedEventArgs e)
        {
            lock (locker)
            {
                Form1.frmDebuglogIsOpen = false;
            }
            debug1 = null;
        }
    }
}

